package com.example.aaaexemplos;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class DAO extends SQLiteOpenHelper {

	private static final String DB_NAME = "aaaExemplosBD";
	private static final int DB_VERSION = 1;
	private static final String CREATE_TABLE_PERSON = "CREATE TABLE pessoas(_id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, telephone TEXT NOT NULL)";
	private static final String TABLE_PERSON = "pessoas";
	private static final String COLUMN_NAME = "name";
	private static final String COLUMN_TELEPHONE = "telephone";

	public DAO(Context context) {
		super(context, DB_NAME, null, DB_VERSION);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(CREATE_TABLE_PERSON);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

	public void save(Person person) {
		ContentValues cv = new ContentValues();
		cv.put(COLUMN_NAME, person.getName());
		cv.put(COLUMN_TELEPHONE, person.getTelephone());

		SQLiteDatabase db = this.getWritableDatabase();
		db.insert(TABLE_PERSON, null, cv);
		db.close();
	}

}
